//
//  UIViewController+QMUIKit.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/11/6.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "UIViewController+QMUIKit.h"
YYSYNTH_DUMMY_CLASS(UIViewController_QMUIKit)
@implementation UIViewController (QMUIKit)
- (UIImage *)navigationBarBackgroundImage
{
        return [UIImage imageWithColor:QMUICMI.whiteColor];
}
- (UIImage *)navigationBarShadowImage
{
        return [UIImage nav_bar_shadows];
}
- (UIColor *)navigationBarTintColor
{
        return QMUICMI.blackColor;
}
- (BOOL)preferredNavigationBarHidden
{
        return self.prefersNavigationBarHidden || self.fd_prefersNavigationBarHidden;
}
- (BOOL)forceEnableInteractivePopGestureRecognizer
{
        return YES;
}
- (BOOL)shouldCustomNavigationBarTransitionIfBarHiddenable
{
        return YES;
}
- (BOOL)shouldCustomNavigationBarTransitionWhenPushAppearing
{
        return YES;
}
- (BOOL)shouldCustomNavigationBarTransitionWhenPushDisappearing
{
        return YES;
}
- (BOOL)shouldCustomNavigationBarTransitionWhenPopAppearing
{
        return YES;
}
- (BOOL)shouldCustomNavigationBarTransitionWhenPopDisappearing
{
        return YES;
}
- (void)configNavigationBar:(BaseNavigationBar *)navigationBar
{
        // 如果要调整左右间距，看 UINavigationBar+WGFix.h
        if ([self.navigationController.viewControllers count] > 1)
        {
                QMUINavigationButton *backBtn = [[QMUINavigationButton alloc] initWithImage:[UIImage nav_ic_back_blackRenderingMode:(UIImageRenderingModeAlwaysOriginal)]];
                UIBarButtonItem *backItem = [QMUINavigationButton barButtonItemWithNavigationButton:backBtn position:(QMUINavigationButtonPositionLeft) target:self action:@selector(backButtonDidClick:)];
                self.navigationItem.leftBarButtonItem = backItem;
        }
        else
        {
                self.navigationItem.leftBarButtonItems = nil;
                self.navigationItem.leftBarButtonItem = nil;
        }
        navigationBar.translucent = NO;
}

- (void)backButtonDidClick:(UIButton *)button
{
        if ([self isKindOfClass:[UINavigationController class]])
        {
                UINavigationController *selfVC = (UINavigationController *)self;
                if (selfVC.viewControllers.count > 1)
                {
                        [selfVC popViewControllerAnimated:YES];
                }
                else
                {
                        if (self.isPresentedByOther)
                        {
                                [self dismissViewControllerAnimated:YES completion:nil];
                        }
                }
        }
        else
        {
                if (self.navigationController.viewControllers.count > 0)
                {
                        [self.navigationController popViewControllerAnimated:YES];
                }
                else if (self.isPresentedByOther)
                {
                        [self dismissViewControllerAnimated:YES completion:nil];
                }
                else
                {
                        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
                }
        }
}

+ (__kindof BaseControllerView * _Nullable)controllerView
{
        return nil;
}

/// RouterHandleProtocol method
+ (nullable UIViewController <JLRRouteDefinitionTargetController> *)targetControllerWithParams:(nullable NSDictionary *)parameters
{
        return nil;
}
@end
